﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MISAPP.MISInterface;
using MISAPP.Classify.Service;

public partial class View_WMG_WMG006_1 : ViewMatrix
{
    string urlString = "../view/WMG/WMG006_1.aspx?node={0}";
    bool showNext = true;
    bool isTop50
    {
        get
        {
            if (ViewState["top50"] == null)
            {
                ViewState["top50"] = HttpContext.Current.Items["top50"];
            }
            return ViewState["top50"] == null
                ? false : true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = "基金庫存分析表";
        limit();
        criteriaList = new string[] { "Criteria", "type","val" };        
        urlString = string.Format(urlString
            , Request.QueryString["node"].ToString());
        Session["val"] = null;
        if (Request.QueryString.Count.Equals(2))
        {
            urlString = string.Format("{0}&val={1}", urlString
                , Request.QueryString[1].ToString() + "{0}" );
            Session["val"] = Request.QueryString[1].ToString();
            string[] tmp = Request.QueryString[1].ToString().Split(new char[] { '_' }
                , StringSplitOptions.RemoveEmptyEntries);
            showNext = tmp.Length.Equals(2) ? false : true;
        }
        else
        {
            urlString = string.Format("{0}&{1}", urlString, "val={0}");
        }

        serviceName = "MISAPP.Classify.Service.Service_WMG006";
        if (!IsPostBack)
        {
            getData();        
        }

    }

    protected void getData()
    {
        string method = isTop50.Equals(false) ? "GetSummaryData"
            : "GetReturnata";

        System.Data.DataTable dt = GetDataFromSerevice(method);
        CLB_Summary.SetData(dt, new string[] { });

    }

    protected void CLB_Summary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (isTop50.Equals(true))
        { return; }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text.Equals("合計"))
            { return; }

            if (string.Empty.Equals(urlString))
            { return; }

            if (!showNext) return;

            string  lnac_id;
            
            HyperLink link = new HyperLink();
            lnac_id = e.Row.Cells[0].Text;
            link.Text = e.Row.Cells[0].Text;
            link.NavigateUrl = string.Format(urlString + "_",
                e.Row.Cells[0].Text.IndexOf('_') > 0
                ? e.Row.Cells[0].Text.Substring(0, e.Row.Cells[0].Text.IndexOf('_'))
                : e.Row.Cells[0].Text);
          
            e.Row.Cells[0].Controls.Add(link);        
        }    
    }

    protected void CLB_Summary_RowCommand(object sender, GridViewCommandEventArgs e)
    {           
    }

    protected void btn2Excel_Click(object sender, EventArgs e)
    {
        serviceName = "MISAPP.Classify.Service.Service_WMG006";
        //criteriaList = new string[] { "Criteria" };

        FillToSession();

        string pageParameter;
        if (isTop50.Equals(true))
        {
            pageParameter = string.Format(
                 "method=GetReturnata&xls=WMG006&service=Service_WMG006&caption={0}&captionRight={1}&toHtmlMethod={2}"
                 , "基金庫存前五十報酬分析表", string.Empty, string.Empty);
        }
        else
        {
            pageParameter = string.Format(
                 "method=GetSummaryData&xls=WMG006&service=Service_WMG006&caption={0}&captionRight={1}&toHtmlMethod={2}"
                 , "基金庫存分析表", string.Empty, string.Empty);
        }
        



        btn2Excel.PreviousPage = "../GV2XLS.aspx";
        btn2Excel.PageParameter = pageParameter;
    }
}
